package com.cskaoyan.utils;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

/**
 * @User: Yr
 * @Date: 2021/12/2
 * @Description: 参数校验工具类
 */


public class ParameterValidationUtil {


    public static void paramValidation(BindingResult bindingResult) {
        if (bindingResult.hasFieldErrors()) {
            FieldError fieldError = bindingResult.getFieldError();
            String field = fieldError.getField();
            String defaultMessage = fieldError.getDefaultMessage();
            throw new IllegalArgumentException("参数有误: " + defaultMessage);
        }
    }
}
